﻿using System;
using fastCSharp;
using fastCSharp.code.cSharp;

namespace diantou.web.exam
{
    /// <summary>
    /// 企业考试答题
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsPage = false)]
    partial class problem : view<problem>
    {
        /// <summary>
        /// 缓存客户端
        /// </summary>
        internal readonly static examAnswerCacheServer.server.tcpClient AnswerCacheClient = new examAnswerCacheServer.server.tcpClient();
        /// <summary>
        /// 考试会话表示
        /// </summary>
        private int sessionId;
        /// <summary>
        /// 跨域验证码
        /// </summary>
        private uint verifyCode;
        /// <summary>
        /// 企业考试答题
        /// </summary>
        /// <returns>是否成功</returns>
        private bool loadView(int examId)
        {
            if (user != null && examUser.ExamId == examId)
            {
                if (examUser.IsRegister)
                {
                    if((examUser.ExamTime == fastCSharp.pub.MinTime || date.NowSecond < examUser.SubmitTime) && !examUser.IsSubmit)
                    {
                        if (load(examId))
                        {
                            if (exam.IsStart && !exam.IsEnd)
                            {
                                sessionId = diantou.examDataAccess.tcpCall.examUser.getSessionId(examUser.Id, out examUser.ExamTime, out examUser.SubmitTime, out verifyCode);
                                if (sessionId != 0) return true;
                            }
                        }
                    }
                    location(new diantou.dataModel.path.exam { Id = examId }.Description);
                }
                else location(new diantou.dataModel.path.exam { Id = examId }.Setting);
                return false;
            }
            if (load(examId))
            {
                switch (exam.Type)
                {
                    case dataModel.exam.type.考生熟悉环境的测试赛:
                    case dataModel.exam.type.完成答卷后发简历的考试:
                    case dataModel.exam.type.预先注册的考试:
                        location(exam.Path.Register);
                        return false;
                }
                location(exam.Path.Index);
            }
            return false;
        }
    }
}